// pages/order-detail/order-detail.js
import {
    request
} from '../../utils/http'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderItemDtos: [],
        remarks: "",
        actualTotal: 0,
        userAddrDto: null,
        orderNumber: "",
        createTime: "",
        status: 0,
        productTotalAmount: '',
        transfee: '',
        reduceAmount: '',
        shopId: '',
        prodid: ''
    },

    // 加载订单数据
    loadOrderDetail(orderNum) {
        let ths = this;
        request({
            url: '/p/myOrder/orderDetail',
            data: {
                orderNumber: orderNum
            },
        }).then(res => {
            ths.setData({
                orderNumber: orderNum,
                actualTotal: res.actualTotal,
                userAddrDto: res.userAddrDto,
                remarks: res.remarks,
                orderItemDtos: res.orderItemDtos,
                createTime: res.createTime,
                status: res.status,
                productTotalAmount: res.orderItemDtos[0].productTotalAmount,
                transfee: res.transfee,
                reduceAmount: res.reduceAmount,
                actualTotal: res.actualTotal,
                shopId: res.shopId
            });
        })
    },
    // 加入购物车
    addToCart(event) {
        let index = event.currentTarget.dataset.index;
        request({
            url: "/p/shopCart/changeItem",
            method: "POST",
            data: {
                basketId: 0,
                count: this.data.orderItemDtos[index].prodCount,
                prodId: this.data.orderItemDtos[index].prodId,
                shopId: this.data.shopId,
                skuId: this.data.orderItemDtos[index].skuId
            },
        }).then(res => {
            wx.showToast({
                title: "加入购物车成功",
                icon: "none"
            })
            wx.switchTab({
                url: '/pages/index/index',
            })
        })
    },
    // 一键复制事件
    copyBtn(e) {
        let ths = this;
        wx.setClipboardData({
            //准备复制的数据
            data: ths.data.orderNumber,
            success(res) {
                wx.showToast({
                    title: '复制成功',
                });
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        
        this.loadOrderDetail(options.orderNum);
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})